﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.models.world.vos.areas {
    import flash.utils.*;
    import __AS3__.vec.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.utils.*;
    import com.adobe.utils.*;

    public class BuildingVO extends AbstractAreaVO implements IAccessible {

        private var _rooms:DictStorage;
        private var _queues:Dictionary;

        public function BuildingVO(_arg1:Object){
            this._rooms = new DictStorage();
            this._queues = new Dictionary();
            super(_arg1);
        }
        public function addRoom(_arg1:IArea):void{
            this._rooms.set(_arg1.id, _arg1);
        }
        public function getRoom(_arg1:String):IArea{
            return ((this._rooms.get(_arg1) as IArea));
        }
        public function hasAreaType(_arg1:String):Boolean{
            var _local2:IArea;
            for each (_local2 in this._rooms.storage) {
                if (_local2.type == _arg1){
                    return (true);
                };
            };
            return (false);
        }
        public function getRoomIdsOfType(_arg1:String, _arg2:Boolean):Array{
            var _local4:IArea;
            var _local5:String;
            var _local6:IRoom;
            var _local3:Array = [];
            _arg1 = _arg1.toLowerCase();
            for each (_local4 in this._rooms.storage) {
                _local5 = _local4.type.toLowerCase();
                if (_local5 == _arg1){
                    _local6 = (_local4 as IRoom);
                    if (_local6){
                        if (((!(_arg2)) || (((_arg2) && (_local6.isFree))))){
                            _local3.push(_local4.id);
                        };
                    };
                };
            };
            return (_local3);
        }
        public function removeRoom(_arg1:String):IArea{
            return ((this._rooms.remove(_arg1) as IArea));
        }
        public function get buildRoomTypes():Array{
            var _local2:IRoom;
            var _local3:IArea;
            var _local1:Array = [];
            for each (_local3 in this._rooms.storage) {
                _local2 = (_local3 as IRoom);
                if (((((_local2) && (_local2.doctor))) && (!(Arrays.contains(_local1, _local2.type))))){
                    _local1.push(_local2.type);
                };
            };
            return (_local1);
        }
        public function isQueued(_arg1:String):Boolean{
            return ((this.getQueue(_arg1).length > 0));
        }
        public function addToQueue(_arg1:String, _arg2:ITreatable):void{
            var _local3:Array = this.getQueue(_arg1);
            if (!ArrayUtil.arrayContainsValue(_local3, _arg2)){
                _local3.push(_arg2);
            };
        }
        public function removeFromQueues(_arg1:String):void{
            var _local2:ITreatable;
            var _local3:Array;
            var _local4:int;
            for each (_local3 in this._queues) {
                _local4 = 0;
                while (_local4 < _local3.length) {
                    _local2 = (_local3[_local4] as ITreatable);
                    if (_local2.id == _arg1){
                        _local3.splice(_local4, 1);
                        break;
                    };
                    _local4++;
                };
            };
        }
        public function getNextInQueue(_arg1:String):ITreatable{
            var _local2:Array = this.getQueue(_arg1);
            return ((_local2.shift() as ITreatable));
        }
        override public function getActor(_arg1:String):IActing{
            var _local2:IActing;
            var _local3:IArea;
            for each (_local3 in this._rooms.storage) {
                if ((_local3 is IAccessible)){
                    _local2 = IAccessible(_local3).getActor(_arg1);
                    if (_local2){
                        break;
                    };
                };
            };
            return (_local2);
        }
        override public function addActor(_arg1:IActing):void{
            var _local2:IAccessible = (this.getRoom(_arg1.roomId) as IAccessible);
            if (_local2){
                _local2.addActor(_arg1);
            } else {
                throw (new Error(((("room " + _arg1.roomId) + " is not accessible for actor ") + _arg1.id)));
            };
        }
        override public function removeActor(_arg1:String):IActing{
            var _local2:IAccessible = this.getRoomOfActor(_arg1);
            if (_local2){
                return (_local2.removeActor(_arg1));
            };
            return (null);
        }
        private function getQueue(_arg1:String):Array{
            this._queues[_arg1] = ((this._queues[_arg1]) || ([]));
            return (this._queues[_arg1]);
        }
        public function get rooms():Dictionary{
            return (this._rooms.storage);
        }
        public function get patientIdList():Vector.<String>{
            return (this.patientsIdList);
        }
        public function getRoomOfActor(_arg1:String):IAccessible{
            var _local2:IAccessible;
            var _local3:IActing;
            var _local4:IArea;
            for each (_local4 in this._rooms.storage) {
                if ((_local4 is IAccessible)){
                    _local3 = IAccessible(_local4).getActor(_arg1);
                    if (_local3){
                        _local2 = (_local4 as IAccessible);
                        break;
                    };
                };
            };
            return (_local2);
        }

    }
}//package net.wooga.pets.models.world.vos.areas 
